package com.borya.action.mobile;

import com.alibaba.fastjson.JSONObject;
import com.borya.action.BaseAction;
import com.borya.constant.SystemConstant;
import com.borya.framework.annotation.Action;
import com.borya.framework.annotation.Autowired;
import com.borya.framework.annotation.JsonResult;
import com.borya.framework.annotation.UrlMapping;
import com.borya.framework.core.ServerRequest;
import com.borya.framework.core.ServerResponse;
import com.borya.service.mobile.SdkService;
import org.apache.log4j.Logger;

@UrlMapping(SystemConstant.Sdk.API_CLIENT_ROOT_PATH)
@Action
public class SdkAction extends BaseAction {

    private Logger log = Logger.getLogger(getClass());
    @Autowired("sdkServiceImpl")
    private SdkService sdkService;

    @UrlMapping(SystemConstant.Sdk.API_METHOD_CHECK)
    @JsonResult
    public String check(ServerRequest request, ServerResponse response) {
        JSONObject json = getJson(request);
        String result = sdkService.check(json);
        log.info("INFO[" + json + "],OUT[" + result + "]");
        return result;
    }

    @UrlMapping(SystemConstant.Sdk.API_METHOD_REGISTER)
    @JsonResult
    public String register(ServerRequest request, ServerResponse response) {
        JSONObject json = getJson(request);
        String result = sdkService.register(json);
        log.info("INFO[" + json + "],OUT[" + result + "]");
        return result;
    }

    @UrlMapping(SystemConstant.Sdk.API_METHOD_UPLOAD_REGISTER_IMAGE)
    @JsonResult
    public String uploadRegisterImg(ServerRequest request, ServerResponse response) {
        JSONObject json = getJson(request);
        String result = sdkService.uploadRegisterImg(json);
        log.info("INFO[" + json + "],OUT[" + result + "]");
        return result;
    }
    @UrlMapping(SystemConstant.Sdk.API_METHOD_LOGIN_CODE)
    @JsonResult
    public String getLoginCode(ServerRequest request, ServerResponse response) {
        JSONObject json = getJson(request);
        String result = sdkService.getLoginCode(json);
        log.info("INFO[" + json + "],OUT[" + result + "]");
        return result;
    }

    @UrlMapping(SystemConstant.Sdk.API_METHOD_LOGIN)
    @JsonResult
    public String login(ServerRequest request, ServerResponse response) {
        JSONObject json = getJson(request);
        String result = sdkService.login(json);
        log.info("INFO[" + json + "],OUT[" + result + "]");
        return result;
    }
}